﻿using System.IO;
using System.Reflection;
using System.Text.Json;

namespace DimensionsHelper.Client.ViewModels;

internal class PresetJsonSource
{
    private const string JsonResourceName = "DimensionsHelper.Client.Resources.PresetJson.json";

    private readonly Dictionary<string, string[]> PresetJsonMap;

    private PresetJsonSource()
    {
        Assembly? assembly = typeof(PresetJsonSource).Assembly;
        using Stream? resourceStream = assembly.GetManifestResourceStream(JsonResourceName);
        if (resourceStream == null)
        {
            PresetJsonMap = [];
            return;
        }

        PresetJsonMap = JsonSerializer.Deserialize<Dictionary<string, string[]>>(resourceStream) ?? [];
    }

    public static PresetJsonSource Instance => new();


    public string[] GetPresetResourceNames(string sectionName)
    {
        return PresetJsonMap.TryGetValue(sectionName, out string[]? names) ? names : [];
    }
}